/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import framework.GameObject;
import framework.Key;
import framework.Screen;
import framework.Util;
import framework.gameAPI.Sprite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;

/**
 *
 * @author edilson
 */
public class Item extends GameObject {

    private Sprite sprite;
    private static final int[] ANIM_ITEM_TIRO1 = {0};
    private static final int[] ANIM_ITEM_TIRO2 = {1};
    private static final int[] ANIM_ITEM_TIRO3 = {2};
    private static final int[] ANIM_ITEM_TIRO4 = {3};
    private static final int[] ANIM_ITEM_TIRO5 = {4};
    private static final int[] ANIM_ITEM_TIRO6 = {5};
    private static final int[] ANIM_ITEM_LIFE = {6};
    private int state;
    public static final int STATE_MOVING = 0;
    public static final int STATE_DEAD = 2;
    private int type;
    public static final int TYPE_TIRO_1 = 1;
    public static final int TYPE_TIRO_2 = 2;
    public static final int TYPE_TIRO_3 = 3;
    public static final int TYPE_TIRO_4 = 4;
    public static final int TYPE_TIRO_5 = 5;
    public static final int TYPE_TIRO_6 = 6;
    public static final int TYPE_LIFE = 7;
    private int cont;

    public Item(int x, int y, int type) {
        power = 1;
        this.image = Util.loadImage(Global.IMG_ITENS);
        this.type = type;

        sprite = new Sprite(image, 25, 25);
        sprite.setAnimationDelay(100);
        this.x = x;
        this.y = y;
        this.width = 25;
        this.height = 25;
        state = STATE_MOVING;
        cont = 0;
        speedY = 2;


        switch (type) {
            case TYPE_TIRO_1:
                sprite.setFrameSequence(ANIM_ITEM_TIRO1);
                break;
            case TYPE_TIRO_2:
                sprite.setFrameSequence(ANIM_ITEM_TIRO2);
                break;
            case TYPE_TIRO_3:
                sprite.setFrameSequence(ANIM_ITEM_TIRO3);
                break;
            case TYPE_TIRO_4:
                sprite.setFrameSequence(ANIM_ITEM_TIRO4);
                break;
            case TYPE_TIRO_5:
                sprite.setFrameSequence(ANIM_ITEM_TIRO5);
                break;
            case TYPE_TIRO_6:
                sprite.setFrameSequence(ANIM_ITEM_TIRO6);
                break;
            case TYPE_LIFE:
                sprite.setFrameSequence(ANIM_ITEM_LIFE);
                break;

        }
    }

    @Override
    public void update() {

        switch (state) {
            case STATE_MOVING:
                cont++;
                if (power <= 0) {
                    state = STATE_DEAD;
                }
                y += speedY;
                break;

            case STATE_DEAD:
                setVisible(false);
                break;
        }

    }

    @Override
    public void paint(Graphics g) {
        if (visible) {
            //g.drawImage(image, x, y, null);
            sprite.setX(x);
            sprite.setY(y);
            sprite.paint(g);
        }
    }

    public int getState() {
        return state;
    }

    public int getType() {
        return type;
    }

    
}
